import MySQLdb

conn = MySQLdb.connect (host = "172.17.23.121", user = "fkong", passwd = "fkong", db = "fkong")
cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]

cursor.execute ("""
	CREATE TABLE TEST
	(
		ID INT,
		COL1 VARCHAR(40),
		COL2 VARCHAR(40),
		COL3 VARCHAR(40)
	)
	""")

cursor.execute ("""
	INSERT INTO TEST (ID, COL1, COL2, COL3)
	VALUES
		(1, 'a', 'b', 'c'),
		(2, 'aa', 'bb', 'cc'),
		(3, 'aaa', 'bbb', 'ccc')
	""")
conn.commit()

cursor.execute ("SELECT * FROM TEST")
rows = cursor.fetchall()
for row in rows:
	print "%d, %s, %s, %s" % (row[0], row[1], row[2], row[3])

print "Number of rows returned: %d" % cursor.rowcount

cursor.execute ("SELECT * FROM TEST")
while (1):
	row = cursor.fetchone()
	if row == None:
		break
	print "%d, %s, %s, %s" % (row[0], row[1], row[2], row[3])
	
print "Number of rows returned: %d" % cursor.rowcount

cursor.close ()
conn.close ()


